<?php
namespace app\service;

/**
 * 五运六气查询服务
 * 根据输入日期返回对应的五运六气信息
 */
class WuyunLiuqi
{
    /**
     * 十天干
     */
    private $tianGan = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'];
    
    /**
     * 十二地支
     */
    private $diZhi = ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥'];
    
    /**
     * 五运六气配置数据
     */
    private $wuyunLiuqiData = [
        // 子年/午年
        'zi_wu' => [
            'dizhi' => ['子', '午'],
            'yinshi' => '多吃咸寒(如海带),中期用苦热(如生姜),后期用酸热(如山楂);热重配苦甘、燥重配苦辛',
            'jichu_qihou' => '上半年少阴君火(偏热),下半年阳明燥金(偏干燥)',
            'special_years' => [
                '壬子' => ['years' => [1972, 2032], 'desc' => '风邪重，易肚子胀'],
                '壬午' => ['years' => [2002, 2062], 'desc' => '风邪重，易肚子胀'],
                '戊子' => ['years' => [1948, 2008, 2068], 'desc' => '天符年（岁会同年，全年气温偏高），气候专一，易引发气太过致病，发病急暴危险：暑热重，易上火、流鼻血'],
                '戊午' => ['years' => [1978, 2038], 'desc' => '天符年（岁会同年，全年气温偏高），气候专一，易引发气太过致病，发病急暴危险：暑热重，易上火、流鼻血'],
                '甲子' => ['years' => [1984, 2044], 'desc' => '湿气重，易身体沉、肚子胀'],
                '甲午' => ['years' => [1954, 2014, 2074], 'desc' => '湿气重，易身体沉、肚子胀'],
                '庚子' => ['years' => [1960, 2020, 2080], 'desc' => '同天符（金运太过，秋季干燥显著）、天刑年：气候和病候具有变化特别剧烈的特征。凉气重，易下半身发凉'],
                '庚午' => ['years' => [1930, 1990, 2050], 'desc' => '同天符（金运太过，秋季干燥显著）、天刑年：气候和病候具有变化特别剧烈的特征。凉气重，易下半身发凉'],
                '丙子' => ['years' => [1996, 2056], 'desc' => '岁会年，水运太过，冬季寒冷加重，全年偏凉：寒气重，易下半身怕冷、生寒病'],
                '丙午' => ['years' => [2006, 2066], 'desc' => '寒气重，易下半身怕冷、生寒病'],
            ],
            'periods' => [
                ['start' => '01-20', 'end' => '03-20', 'zhuqi' => '风木', 'keqi' => '寒水', 'qihou' => '偏冷', 'desc' => '关节僵硬、腰椎痛、身体内外长疮'],
                ['start' => '03-21', 'end' => '05-21', 'zhuqi' => '君火', 'keqi' => '风木', 'qihou' => '偏风、热', 'desc' => '眼睛发红、看不清、上半身热、下半身小便不畅'],
                ['start' => '05-22', 'end' => '07-22', 'zhuqi' => '相火', 'keqi' => '君火', 'qihou' => '偏热', 'desc' => '突然心痛、忽冷忽热、咳嗽气喘、眼睛发红'],
                ['start' => '07-23', 'end' => '09-22', 'zhuqi' => '湿土', 'keqi' => '湿土', 'qihou' => '偏湿', 'desc' => '忽冷忽热、咽干、长黄疸、流鼻血'],
                ['start' => '09-23', 'end' => '11-22', 'zhuqi' => '燥金', 'keqi' => '相火', 'qihou' => '偏热、燥', 'desc' => '温热类疾病（如风热感冒）'],
                ['start' => '11-23', 'end' => '01-19', 'zhuqi' => '寒水', 'keqi' => '燥金', 'qihou' => '偏干燥、冷', 'desc' => '上半身浮肿、眼角长疮、咳嗽咳血、寒气入胃致心痛'],
            ]
        ],
        
        // 丑年/未年
        'chou_wei' => [
            'dizhi' => ['丑', '未'],
            'yinshi' => '多吃苦热,中期用酸和(如小米),后期用甘热(如红枣);湿重配酸辛、寒重配苦辛',
            'jichu_qihou' => '上半年太阴湿土(偏湿),下半年太阳寒水(偏寒)',
            'special_years' => [
                '己丑' => ['years' => [1949, 2009, 2069], 'desc' => '天符年,发病急'],
                '己未' => ['years' => [1979, 2039], 'desc' => '天符年,发病急'],
                '辛丑' => ['years' => [1961, 2021, 2081], 'desc' => '天刑年,气候病候变化剧烈'],
                '辛未' => ['years' => [1991, 2051], 'desc' => '天刑年,气候病候变化剧烈'],
            ],
            'periods' => [
                ['start' => '01-20', 'end' => '03-20', 'zhuqi' => '风木', 'keqi' => '风木', 'qihou' => '偏风', 'desc' => '流鼻血、筋络僵硬、关节不灵活、身体沉、筋肉无力'],
                ['start' => '03-21', 'end' => '05-21', 'zhuqi' => '君火', 'keqi' => '君火', 'qihou' => '偏热', 'desc' => '爆发传染病（远近都可能中招）'],
                ['start' => '05-22', 'end' => '07-22', 'zhuqi' => '相火', 'keqi' => '湿土', 'qihou' => '偏湿、热', 'desc' => '外感寒湿、身体沉、浮肿、胸口/肚子胀'],
                ['start' => '07-23', 'end' => '09-22', 'zhuqi' => '湿土', 'keqi' => '相火', 'qihou' => '偏湿、热', 'desc' => '皮肤发热、突然流鼻血、疟疾、胸口/肚子热胀、严重时浮肿'],
                ['start' => '09-23', 'end' => '11-22', 'zhuqi' => '燥金', 'keqi' => '燥金', 'qihou' => '偏燥', 'desc' => '皮肤问题（干燥、长疹子）'],
                ['start' => '11-23', 'end' => '01-19', 'zhuqi' => '寒水', 'keqi' => '寒水', 'qihou' => '偏寒', 'desc' => '外感寒邪、关节僵硬、腰椎痛'],
            ]
        ],
        
        // 寅年/申年
        'yin_shen' => [
            'dizhi' => ['寅', '申'],
            'yinshi' => '多吃咸寒,中期用苦热,后期用酸热;热重配苦甘、燥重配苦辛(或以酸冷为主)',
            'jichu_qihou' => '上半年少阳相火(偏热),下半年厥阴风木(偏风)',
            'special_years' => [
                '壬寅' => ['years' => [1962, 2022, 2082], 'desc' => '同天符（木运太过，春季风象明显）年：风邪重，易头晕、肢体震颤、肋骨疼、受惊'],
                '壬申' => ['years' => [1992, 2052], 'desc' => '同天符（木运太过，春季风象明显）年：风邪重，易头晕、肢体震颤、肋骨疼、受惊'],
                '戊寅' => ['years' => [1998, 2058], 'desc' => '天符年，气候专一，易引发气太过致病，发病急暴危险：暑热重，易上半身热郁、流鼻血、便血、心痛'],
                '戊申' => ['years' => [1968, 2028], 'desc' => '天符年，气候专一，易引发气太过致病，发病急暴危险：暑热重，易上半身热郁、流鼻血、便血、心痛'],
                '甲寅' => ['years' => [1974, 2034], 'desc' => '湿气重，易身体沉、浮肿、胸口闷'],
                '甲申' => ['years' => [2004, 2064], 'desc' => '湿气重，易身体沉、浮肿、胸口闷'],
                '庚寅' => ['years' => [2010, 2070], 'desc' => '天刑年，气候和病候具有变化特别剧烈的特征：凉气重，易肩背、胸口疼'],
                '庚申' => ['years' => [1980, 2040], 'desc' => '天刑年，气候和病候具有变化特别剧烈的特征：凉气重，易肩背、胸口疼'],
                '丙寅' => ['years' => [1986, 2046], 'desc' => '寒气重，易怕冷、浮肿'],
                '丙申' => ['years' => [1956, 2016], 'desc' => '寒气重，易怕冷、浮肿'],
            ],
            'periods' => [
                ['start' => '01-20', 'end' => '03-20', 'zhuqi' => '风木', 'keqi' => '君火', 'qihou' => '偏热', 'desc' => '温病流行、气往上涌、流鼻血、眼睛发红、咳嗽头痛、皮肤长疮'],
                ['start' => '03-21', 'end' => '05-21', 'zhuqi' => '君火', 'keqi' => '湿土', 'qihou' => '偏湿、热', 'desc' => '热邪上涌、咳嗽呕吐、胸口/喉咙不适、头痛发热、神志不清、生疮'],
                ['start' => '05-22', 'end' => '07-22', 'zhuqi' => '相火', 'keqi' => '相火', 'qihou' => '偏热', 'desc' => '中暑、耳鸣、流鼻血、脓疮、喉咙疼、眼睛发红、严重时猝死'],
                ['start' => '07-23', 'end' => '09-22', 'zhuqi' => '湿土', 'keqi' => '燥金', 'qihou' => '偏湿、燥', 'desc' => '全身发沉'],
                ['start' => '09-23', 'end' => '11-22', 'zhuqi' => '燥金', 'keqi' => '寒水', 'qihou' => '偏燥、冷', 'desc' => '易受寒气影响，出现干燥+怕冷症状'],
                ['start' => '11-23', 'end' => '01-19', 'zhuqi' => '寒水', 'keqi' => '风木', 'qihou' => '偏风、冷', 'desc' => '小便失禁、心痛、咳嗽'],
            ]
        ],
        
        // 卯年/酉年
        'mao_you' => [
            'dizhi' => ['卯', '酉'],
            'yinshi' => '多吃咸寒,中期用咸温(如咸鱼),后期用辛温(如辣椒);燥重配酸辛、热重配甘苦',
            'jichu_qihou' => '上半年阳明燥金(偏干燥),下半年少阴君火(偏热)',
            'special_years' => [
                '乙卯' => ['years' => [1975, 2035], 'desc' => '天符年,发病急'],
                '乙酉' => ['years' => [1945, 2005], 'desc' => '天符年,发病急'],
                '丁卯' => ['years' => [1987, 2047], 'desc' => '天刑年,气候病候变化剧烈'],
                '丁酉' => ['years' => [1957, 2017], 'desc' => '天刑年,气候病候变化剧烈'],
            ],
            'periods' => [
                ['start' => '01-20', 'end' => '03-20', 'zhuqi' => '风木', 'keqi' => '湿土', 'qihou' => '偏湿', 'desc' => '肚子热胀、脸/眼睛浮肿、流鼻血、打喷嚏、小便发黄、严重时小便不畅'],
                ['start' => '03-21', 'end' => '05-21', 'zhuqi' => '君火', 'keqi' => '相火', 'qihou' => '偏热', 'desc' => '爆发传染病（死亡率高）'],
                ['start' => '05-22', 'end' => '07-22', 'zhuqi' => '相火', 'keqi' => '燥金', 'qihou' => '偏燥、热', 'desc' => '忽冷忽热、发抖'],
                ['start' => '07-23', 'end' => '09-22', 'zhuqi' => '湿土', 'keqi' => '寒水', 'qihou' => '偏湿、冷', 'desc' => '突然晕倒、发抖、说胡话、没力气、咽干口渴、心痛、生疮'],
                ['start' => '09-23', 'end' => '11-22', 'zhuqi' => '燥金', 'keqi' => '风木', 'qihou' => '偏燥、风', 'desc' => '易受风邪影响，出现干燥+肢体不适症状'],
                ['start' => '11-23', 'end' => '01-19', 'zhuqi' => '寒水', 'keqi' => '君火', 'qihou' => '偏热、冷', 'desc' => '温热类疾病'],
            ]
        ],
        
        // 辰年/戌年
        'chen_xu' => [
            'dizhi' => ['辰', '戌'],
            'yinshi' => '多吃苦温,中期用甘和,后期用甘温;寒重配甘苦、湿重配酸淡',
            'jichu_qihou' => '上半年太阳寒水(偏寒),下半年太阴湿土(偏湿)',
            'special_years' => [
                '壬辰' => ['years' => [1952, 2012], 'desc' => '易头晕、看不清东西'],
                '壬戌' => ['years' => [1982, 2042], 'desc' => '易头晕、看不清东西'],
                '戊辰' => ['years' => [1988, 2048], 'desc' => '天刑年，气候和病候具有变化特别剧烈的特征：易热邪郁结'],
                '戊戌' => ['years' => [1958, 2018], 'desc' => '天刑年，气候和病候具有变化特别剧烈的特征：易热邪郁结'],
                '甲辰' => ['years' => [1964, 2024], 'desc' => '同天符（岁会年，全年偏湿）（土运太过，湿气加重）年：易湿气重、下半身不适'],
                '甲戌' => ['years' => [1994, 2054], 'desc' => '同天符（岁会年，全年偏湿）（土运太过，湿气加重）年：易湿气重、下半身不适'],
                '庚辰' => ['years' => [1940, 2000, 2060], 'desc' => '易干燥、后背沉、胸口胀'],
                '庚戌' => ['years' => [1970, 2030], 'desc' => '易干燥、后背沉、胸口胀'],
                '丙辰' => ['years' => [1976, 2036], 'desc' => '天符年，气候专一，易引发气太过致病，发病急暴危险：易受大寒影响，关节（筋骨关节间气血津液流通的缝隙）不适'],
                '丙戌' => ['years' => [2006, 2066], 'desc' => '天符年，气候专一，易引发气太过致病，发病急暴危险：易受大寒影响，关节（筋骨关节间气血津液流通的缝隙）不适'],
            ],
            'periods' => [
                ['start' => '01-20', 'end' => '03-20', 'zhuqi' => '风木', 'keqi' => '相火', 'qihou' => '偏热', 'desc' => '温病/传染病流行、身体发热、头痛、呕吐、皮肤长疮'],
                ['start' => '03-21', 'end' => '05-21', 'zhuqi' => '君火', 'keqi' => '燥金', 'qihou' => '偏燥、热', 'desc' => '气郁结、肚子胀、拉肚子、腿软无力'],
                ['start' => '05-22', 'end' => '07-22', 'zhuqi' => '相火', 'keqi' => '寒水', 'qihou' => '偏冷、热', 'desc' => '忽冷忽热、生痈疽、拉肚子、心烦、胸口闷'],
                ['start' => '07-23', 'end' => '09-22', 'zhuqi' => '湿土', 'keqi' => '风木', 'qihou' => '偏湿、风', 'desc' => '高热、没力气、肌肉萎缩、腿软、拉肚子（带红白黏液）、流鼻血'],
                ['start' => '09-23', 'end' => '11-22', 'zhuqi' => '燥金', 'keqi' => '君火', 'qihou' => '偏燥、热', 'desc' => '易受热邪影响，出现干燥+发热症状'],
                ['start' => '11-23', 'end' => '01-19', 'zhuqi' => '寒水', 'keqi' => '湿土', 'qihou' => '偏湿、冷', 'desc' => '易受寒湿影响，出现怕冷+身体沉症状'],
            ]
        ],
        
        // 巳年/亥年
        'si_hai' => [
            'dizhi' => ['巳', '亥'],
            'yinshi' => '多吃辛凉(如薄荷),中期用甘和,后期用咸寒;风重配苦甘、火重配苦辛',
            'jichu_qihou' => '上半年厥阴风木(偏风),下半年少阳相火(偏热)',
            'special_years' => [
                '丁巳' => ['years' => [1977, 2037], 'desc' => '天符年,发病急'],
                '丁亥' => ['years' => [2007, 2067], 'desc' => '天符年,发病急'],
                '己巳' => ['years' => [1989, 2049], 'desc' => '天刑年,气候病候变化剧烈'],
                '己亥' => ['years' => [1959, 2019], 'desc' => '天刑年,气候病候变化剧烈'],
            ],
            'periods' => [
                ['start' => '01-20', 'end' => '03-20', 'zhuqi' => '风木', 'keqi' => '燥金', 'qihou' => '偏燥、风', 'desc' => '下半身右侧发凉、生寒病'],
                ['start' => '03-21', 'end' => '05-21', 'zhuqi' => '君火', 'keqi' => '寒水', 'qihou' => '偏冷、热', 'desc' => '上半身中间发热'],
                ['start' => '05-22', 'end' => '07-22', 'zhuqi' => '相火', 'keqi' => '风木', 'qihou' => '偏风、热', 'desc' => '耳鸣、头晕、肢体震颤、流眼泪'],
                ['start' => '07-23', 'end' => '09-22', 'zhuqi' => '湿土', 'keqi' => '君火', 'qihou' => '偏湿、热', 'desc' => '长黄疸、身体浮肿'],
                ['start' => '09-23', 'end' => '11-22', 'zhuqi' => '燥金', 'keqi' => '湿土', 'qihou' => '偏燥、湿', 'desc' => '易受湿气影响，出现干燥+身体沉症状'],
                ['start' => '11-23', 'end' => '01-19', 'zhuqi' => '寒水', 'keqi' => '相火', 'qihou' => '偏热、冷', 'desc' => '温热类疾病'],
            ]
        ],
    ];
    
    /**
     * 查询五运六气信息
     * @param string $date 日期格式 Y-m-d 如: 2024-03-15
     * @return array 返回五运六气信息
     */
    public function query($date)
    {
        try {
            // 解析日期
            $timestamp = strtotime($date);
            if (!$timestamp) {
                return ['error' => '日期格式错误,请使用 Y-m-d 格式,如: 2024-03-15'];
            }
            
            $year = date('Y', $timestamp);
            $month = date('m', $timestamp);
            $day = date('d', $timestamp);
            
            // 获取农历年份的天干地支
            $paipan = new paipan();
            $ganzhi = $this->getYearGanZhi($year);
            
            // 获取年份类型
            $yearType = $this->getYearType($ganzhi['dizhi']);
            
            if (!$yearType) {
                return ['error' => '无法识别年份类型'];
            }
            
            // 获取基础数据
            $baseData = $this->wuyunLiuqiData[$yearType];
            
            // 判断特殊年份
            $specialInfo = $this->getSpecialYearInfo($ganzhi['ganzhi'], $year, $baseData['special_years']);
            
            // 获取当前时段信息
            $periodInfo = $this->getPeriodInfo($month, $day, $baseData['periods']);
            
            // 组装返回数据
            return [
                'success' => true,
                'date' => $date,
                'year' => $year,
                'ganzhi' => $ganzhi['ganzhi'],
                'ganzhi_cn' => $ganzhi['ganzhi'] . '年',
                'year_type' => $this->getYearTypeName($yearType),
                'yinshi_tiaoli' => $baseData['yinshi'],
                'jichu_qihou' => $baseData['jichu_qihou'],
                'special_info' => $specialInfo,
                'current_period' => $periodInfo,
                'tongyong_guilu' => '年运太过时,主要损伤六腑,对五脏无明显损伤'
            ];
            
        } catch (\Exception $e) {
            return ['error' => $e->getMessage()];
        }
    }
    
    /**
     * 获取年份的天干地支
     * @param int $year 公历年份
     * @return array
     */
    private function getYearGanZhi($year)
    {
        // 1984年是甲子年(第一个甲子年的开始)
        $baseYear = 1984;
        $offset = ($year - $baseYear) % 60;
        if ($offset < 0) {
            $offset += 60;
        }
        
        $ganIndex = $offset % 10;
        $zhiIndex = $offset % 12;
        
        return [
            'tiangan' => $this->tianGan[$ganIndex],
            'dizhi' => $this->diZhi[$zhiIndex],
            'ganzhi' => $this->tianGan[$ganIndex] . $this->diZhi[$zhiIndex]
        ];
    }
    
    /**
     * 根据地支确定年份类型
     * @param string $dizhi 地支
     * @return string|null
     */
    private function getYearType($dizhi)
    {
        $typeMap = [
            '子' => 'zi_wu',
            '午' => 'zi_wu',
            '丑' => 'chou_wei',
            '未' => 'chou_wei',
            '寅' => 'yin_shen',
            '申' => 'yin_shen',
            '卯' => 'mao_you',
            '酉' => 'mao_you',
            '辰' => 'chen_xu',
            '戌' => 'chen_xu',
            '巳' => 'si_hai',
            '亥' => 'si_hai',
        ];
        
        return $typeMap[$dizhi] ?? null;
    }
    
    /**
     * 获取年份类型名称
     * @param string $yearType
     * @return string
     */
    private function getYearTypeName($yearType)
    {
        $nameMap = [
            'zi_wu' => '子年/午年(鼠年/马年)',
            'chou_wei' => '丑年/未年(牛年/羊年)',
            'yin_shen' => '寅年/申年(虎年/猴年)',
            'mao_you' => '卯年/酉年(兔年/鸡年)',
            'chen_xu' => '辰年/戌年(龙年/狗年)',
            'si_hai' => '巳年/亥年(蛇年/猪年)',
        ];
        
        return $nameMap[$yearType] ?? '';
    }
    
    /**
     * 获取特殊年份信息
     * @param string $ganzhi 天干地支
     * @param int $year 年份
     * @param array $specialYears 特殊年份配置
     * @return array
     */
    private function getSpecialYearInfo($ganzhi, $year, $specialYears)
    {
        if (isset($specialYears[$ganzhi])) {
            $info = $specialYears[$ganzhi];
            if (in_array($year, $info['years'])) {
                return [
                    'is_special' => true,
                    'ganzhi' => $ganzhi,
                    'description' => $info['desc']
                ];
            }
        }
        
        return [
            'is_special' => false,
            'description' => '普通年份'
        ];
    }
    
    /**
     * 获取该地支类型下所有特殊年份的详细信息
     * @param array $specialYears 特殊年份配置
     * @return array
     */
    private function getAllSpecialYearsInfo($specialYears)
    {
        $result = [];
        
        foreach ($specialYears as $ganzhi => $info) {
            $yearsStr = implode('、', $info['years']);
            $result[] = [
                'ganzhi' => $ganzhi,
                'years' => $info['years'],
                'years_str' => $yearsStr,
                'description' => $info['desc'],
                'full_text' => $ganzhi . ' ' . $yearsStr . ' ' . $info['desc']
            ];
        }
        
        return $result;
    }
    
    /**
     * 获取当前时段信息
     * @param string $month 月份
     * @param string $day 日期
     * @param array $periods 时段配置
     * @return array
     */
    private function getPeriodInfo($month, $day, $periods)
    {
        $currentDate = sprintf('%02d-%02d', $month, $day);
        
        foreach ($periods as $period) {
            $start = $period['start'];
            $end = $period['end'];
            
            // 处理跨年的情况(11-23 到 01-19)
            if ($start > $end) {
                // 跨年时段
                if ($currentDate >= $start || $currentDate <= $end) {
                    return [
                        'period' => $start . ' ~ ' . $end,
                        'zhuqi' => $period['zhuqi'] ?? '',
                        'keqi' => $period['keqi'] ?? '',
                        'qihou' => $period['qihou'] ?? '',
                        'description' => $period['desc']
                    ];
                }
            } else {
                // 正常时段
                if ($currentDate >= $start && $currentDate <= $end) {
                    return [
                        'period' => $start . ' ~ ' . $end,
                        'zhuqi' => $period['zhuqi'] ?? '',
                        'keqi' => $period['keqi'] ?? '',
                        'qihou' => $period['qihou'] ?? '',
                        'description' => $period['desc']
                    ];
                }
            }
        }
        
        return [
            'period' => '未知时段',
            'zhuqi' => '',
            'keqi' => '',
            'qihou' => '',
            'description' => '无法确定当前时段'
        ];
    }
    
    /**
     * 批量查询多个日期
     * @param array $dates 日期数组
     * @return array
     */
    public function batchQuery($dates)
    {
        $results = [];
        foreach ($dates as $date) {
            $results[] = $this->query($date);
        }
        return $results;
    }
    
    /**
     * 获取年份所有时段信息
     * @param string $date 日期
     * @return array
     */
    public function getYearAllPeriods($date)
    {
        $result = $this->query($date);
        
        if (isset($result['error'])) {
            return $result;
        }
        
        $yearType = $this->getYearType($result['dizhi']);
        $baseData = $this->wuyunLiuqiData[$yearType];
        
        return [
            'success' => true,
            'ganzhi' => $result['ganzhi'],
            'year_type' => $result['year_type'],
            'all_periods' => $baseData['periods']
        ];
    }
    
    /**
     * 获取年份完整信息（包括所有时段，不筛选当前时段）
     * @param string $date 日期
     * @return array
     */
    public function getYearFullInfo($date)
    {
        try {
            // 【新版本标记 - 2025-10-30】此方法返回完整的五运六气信息
            // 解析日期
            $timestamp = strtotime($date);
            if (!$timestamp) {
                return ['error' => '日期格式错误,请使用 Y-m-d 格式,如: 2024-03-15'];
            }
            
            $year = date('Y', $timestamp);
            
            // 获取农历年份的天干地支
            $paipan = new paipan();
            $ganzhi = $this->getYearGanZhi($year);
            
            // 获取年份类型
            $yearType = $this->getYearType($ganzhi['dizhi']);
            
            if (!$yearType) {
                return ['error' => '无法识别年份类型'];
            }
            
            // 获取基础数据
            $baseData = $this->wuyunLiuqiData[$yearType];
            
            // 判断当前年份是否为特殊年份
            $specialInfo = $this->getSpecialYearInfo($ganzhi['ganzhi'], $year, $baseData['special_years']);
            
            // 获取该地支类型下所有特殊年份的详细信息
            $allSpecialYears = $this->getAllSpecialYearsInfo($baseData['special_years']);
            
            // 组装返回数据（不包含当前时段，返回所有时段和所有特殊年份）
            return [
                'success' => true,
                'version' => 'v2_full_info', // 版本标记，用于区分新旧版本
                'date' => $date,
                'year' => $year,
                'ganzhi' => $ganzhi['ganzhi'],
                'ganzhi_cn' => $ganzhi['ganzhi'] . '年',
                'year_type' => $this->getYearTypeName($yearType),
                'yinshi_tiaoli' => $baseData['yinshi'],
                'jichu_qihou' => $baseData['jichu_qihou'],
                'special_info' => $specialInfo, // 当前年份是否为特殊年份
                'all_special_years' => $allSpecialYears, // 该地支类型下所有特殊年份
                'all_periods' => $baseData['periods'], // 返回所有时段
                'tongyong_guilu' => '年运太过时,主要损伤六腑,对五脏无明显损伤'
            ];
            
        } catch (\Exception $e) {
            return ['error' => $e->getMessage()];
        }
    }
}
